﻿using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;

namespace IdentityManagement
{
    public class IdentityDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        public const string AdminPhoneNumberPropertyName = "AdminPhoneNumber";
        public const string AdminPhoneNumberDefaultValue = "16800000000";
        public const string AdminEmailPropertyName = "AdminEmail";
        public const string AdminEmailDefaultValue = "admin@xms.io";
        public const string AdminPasswordPropertyName = "AdminPassword";
        public const string AdminPasswordDefaultValue = "1q2w3E*";
        public const string TenantNamePropertyName = "TenantName";
        public const string TenantDisplayNamePropertyName = "TenantDisplayName";
        public const string RootOUExtraProperties = "RootOUExtraProperties";
        public const string AdminExtraProperties = "AdminExtraProperties";
        public const string AdminRoleExtraProperties = "AdminRoleExtraProperties";

        protected IIdentityDataSeeder IdentityDataSeeder { get; }

        public IdentityDataSeedContributor(IIdentityDataSeeder identityDataSeeder)
        {
            IdentityDataSeeder = identityDataSeeder;
        }

        public virtual async Task SeedAsync(DataSeedContext context)
        {
            await IdentityDataSeeder.SeedAsync(
                context?[AdminPhoneNumberPropertyName] as string ?? AdminPhoneNumberDefaultValue,
                context?[AdminEmailPropertyName] as string ?? AdminEmailDefaultValue,
                context?[AdminPasswordPropertyName] as string ?? AdminPasswordDefaultValue,
                context?.TenantId,
                context?[TenantNamePropertyName] as string,
                context?[TenantDisplayNamePropertyName] as string,
                context?[RootOUExtraProperties] as ExtraPropertyDictionary,
                context?[AdminExtraProperties] as ExtraPropertyDictionary,
                context?[AdminRoleExtraProperties] as ExtraPropertyDictionary
            );
        }
    }
}
